/* 毫秒转换 */
export const durationTrans = mss => {
  let b = ''
  let h = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
    m = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60)),
    s = parseInt((mss % (1000 * 60)) / 1000)
  if (h > 0) {
    h = h < 10 ? '0' + h : h
    b += h + ':'
  }
  m = m < 10 ? '0' + m : m
  s = s < 10 ? '0' + s : s
  b += m + ':' + s
  return b
}

// 日期转换
export const getGMT = dateTime => {
  if (dateTime === null) {
    return ''
  }
  let date = new Date(parseInt(dateTime) * 1000)
  let now = new Date().getTime()
  let second = Math.floor((now - date) / 1000)
  let minute = Math.floor(second / 60)
  let hour = Math.floor(minute / 60)
  let day = Math.floor(hour / 24)
  let month = Math.floor(day / 31)
  let year = Math.floor(month / 12)
  let Year = date.getFullYear()
  let Moth =
    date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1
  let Day = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()
  if (year > 0) {
    return `${Year}-${Moth}-${Day}`
  } else if (day > 0) {
    return `${Moth}-${Day}`
  } else if (hour > 0) {
    return hour + '小时前'
  } else if (minute > 0) {
    return minute + '分钟前'
  } else if (second > 0) {
    return second + '秒前'
  } else {
    return '刚刚'
  }
}

// 数量转换
export const toNums = num => {
  let n = num + ''
  if (n >= 10000 && n <= 100000) {
    return n.slice(0, 1) + '万+'
  }
  if (n >= 100000 && n <= 1000000) {
    return n.slice(0, 2) + '万+'
  }
  if (n >= 1000000) {
    return n.slice(0, 3) + '万+'
  }
  return n
}
